using System;
using System.Web;
using System.Web.UI;

namespace ScottCateAjax2008.Utilities
{
    /// <summary>
    /// Summary description for Utils
    /// </summary>
    public static class Utils
    {
        public static string ScriptName
        {
            get { return HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]; }
        }

        /// <summary>
        /// Stolen from asp.net/forums -- This is not a supported feature
        /// http://forums.asp.net/2/1256245/ShowThread.aspx
        /// </summary>
        /// <param name="scriptName"></param>
        /// <param name="context"></param>
        /// <param name="clientScript"></param>
        public static void OverrideAtlasScript(
            string scriptName,
            HttpContext context,
            ClientScriptManager clientScript)
        {
            string scriptResourceNameFormat = "Microsoft.Web.Resources.ScriptLibrary.{0}.{1}";
            string scriptFlavor = context.IsDebuggingEnabled ? "Debug" : "Release";
            string scriptResourceName = String.Format(scriptResourceNameFormat, scriptFlavor, scriptName);

            string key = clientScript.GetWebResourceUrl(typeof(ScriptManager), scriptResourceName);
            string url = String.Format("/AdvancedAjax/ScriptLibrary/Atlas/{0}/{1}", scriptFlavor, scriptName);

            clientScript.RegisterClientScriptInclude(typeof(ScriptManager), key, url);
        }
    }
}